package com.asktgapp.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.Display;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import com.asktgapp.R;

/**
 * time:2018/1/31
 * Create By ZhaoKai
 * Email: dczk@foxmail.com
 * Description:
 */

public class PublishSuccessDialog extends DialogFragment {
    private onDissmissListener onDissmissListener;

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = new Dialog(getContext());
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.dialog_publish_success);
        Window window = dialog.getWindow();
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        WindowManager.LayoutParams params = window.getAttributes();
        WindowManager windowManager = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
        window.setBackgroundDrawableResource(R.drawable.dialog_bg);
        Display display = windowManager.getDefaultDisplay();
        params.width = display.getWidth() * 3 / 5;
        params.gravity = Gravity.CENTER;
        params.windowAnimations = R.style.popwin_anim_style;
        window.setAttributes(params);
        return dialog;
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        if (onDissmissListener != null) {
            onDissmissListener.onDismiss();
        }
        super.onDismiss(dialog);
    }

    public interface onDissmissListener {
        void onDismiss();
    }

    public void setOnDismiss(onDissmissListener listener) {
        this.onDissmissListener = listener;
    }
}
